package recursion;

import java.util.LinkedList;

/**
 * 汉诺塔
 *
 * @author yyz
 * @create 2023-11-15 15:06
 */
public class 汉诺塔 {
    private static LinkedList<Integer> a = new LinkedList<>();
    private static LinkedList<Integer> b = new LinkedList<>();
    private static LinkedList<Integer> c = new LinkedList<>();

    private static void init(int n) {
        for (int i = n; i >= 1; i--) {
            a.add(i);
        }
    }

    /**
     * 移动圆盘
     *
     * @param n 圆盘个数
     * @param a 源
     * @param b 借
     * @param c 目标
     */
    private static void move(int n, LinkedList<Integer> a,
                             LinkedList<Integer> b,
                             LinkedList<Integer> c) {
        if (n == 0) {
            return;
        }

        move(n - 1, a, c, b);
        c.addLast(a.removeLast());
        print();
        move(n - 1, b, a, c);
    }

    private static void print() {
        System.out.println("-----------------------");
        System.out.println(a);
        System.out.println(b);
        System.out.println(c);
    }

    public static void main(String[] args) {
        init(64);
        print();
        move(64, a, b, c);
    }
}
